$(document).ready(function () {
    
    
    $('#table-modal tr').click(function () {
        var tds = $(this).children('td');
        var ths = $('#table-modal thead tr').children();
        var tableModal_tbody = $('.table-exam');
        tableModal_tbody.append('<tbody/>');
        for(var i = 0; i < tds.length; i++){
            
            console.log();
            var th = $('<th/>').text($(ths[i]).text());
            var td = $('<td/>').text($(tds[i]).text());

            var tr = $('<tr/>').append(th,td);
            tableModal_tbody.append(tr);
        }
        
        var url = $(this).data('url');
        if($(tds[tds.length-1]).text() == '未考'){
            var modal = $('.modal-footer');
            $(modal).find('button').last().text('开始考试');
            $(modal).find('button').last().click(function(){
                window.location.href = url;
            })

        }else{
            $('.modal-footer').find('button').last().text('查看试卷');
            $('.modal-footer').find('button').last().click(function(){
                window.location.href = url;
            })
        }
    })

    $('#myModal').on('hidden.bs.modal', 
    function(){
        $('.table-exam tbody').remove();
    })

    var exampapers = [
        ["1243","Bootstrap框架与应用","24分钟/60分钟","40/60","28/40","/","/","68/100","已考"],
    ]

    // initPapers();

    function initPapers(){
        var tr = $('#table-modal tbody tr',{});
        for(let i in exampapers){
            for(let j in exampapers[i]){
                if(exampapers[i][j].search('/') != -1){
                    var greenText = exampapers[i][j].substring(0, exampapers[i][j].search('/'));
                    var normalText = exampapers[i][j].substring(exampapers[i][j].search('/')+1, exampapers[i][j].length);
                    var td = $('<td><span class = "gb">'+ greenText +'</span>'+ normalText +'<td/>');
                    tr.append(td);
                }else{
                    var td = $('<td>').text(exampapers[i][j]);
                    tr.append(td);
                }
            }
        }
    }

    $('input[name=exam_search]').bind('input porpertychange',function(){
        console.log($(this).val());



    })

})